<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getOperationLogs">查询</el-button>
        </el-form-item>
<!--        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>-->
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="operationLogs" highlight-current-row
              @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="userId" label="操作人id">
      </el-table-column>
      <el-table-column prop="operationObject" label="操作对象">
      </el-table-column>
      <el-table-column prop="operationType" label="操作类型">
      </el-table-column>
      <el-table-column prop="operationTime" label="操作时间">
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
<!--          <el-button size="small" @click="handlesave(scope.$index, scope.row)">编辑</el-button>-->
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 20, 30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          style="float:right;">
      </el-pagination>
    </el-col>

    <!--新增或编辑界面-->
<!--    <el-dialog :title="title" :visible.sync="saveFormVisible" :close-on-click-modal="false">
      <el-form :model="saveForm" label-width="80px" :rules="saveFormRules" ref="saveForm">
        <el-form-item label="部门名称" prop="name">
          <el-input v-model="saveForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="部门编号" prop="sn">
          <el-input v-model="saveForm.sn" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="部门状态" prop="state">
          <el-radio-group v-model="saveForm.state">
            <el-radio class="radio" :label="1">启用</el-radio>
            <el-radio class="radio" :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="部门经理" prop="managerId">
          &lt;!&ndash;          <el-input v-model="saveForm.managerId" auto-complete="off"></el-input>&ndash;&gt;
          <template>
            <el-select v-model="saveForm.managerId" placeholder="请选择">
              <el-option
                  v-for="item in managers"
                  :label="item.username"
                  :value="item.id"
                  :key="item.id">

                <span style="float: left">{{ item.username }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.phone }}</span>
              </el-option>
            </el-select>
          </template>
        </el-form-item>
        <el-form-item class="block" label="上级部门" prop="parentId" >
          &lt;!&ndash;          <el-input v-model="saveForm.parentId" auto-complete="off"></el-input>&ndash;&gt;
          <span class="demonstration"></span>
          <el-cascader v-model="saveForm.parentId"
                       :options="options"
                       :props="{
                checkStrictly: true,
                label: 'name',
                value: 'id',
                emitPath: true,

              }"
                       clearable></el-cascader>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="saveFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="saveSubmit" :loading="saveLoading">提交</el-button>
      </div>
    </el-dialog>-->


  </section>
</template>


<script>

import {title} from "mockjs/src/mock/random/text";
import util from "../../common/js/util";

export default {
  data() {
    return {
      filters: {
        keyword: ''
      },
/*      title: '',*/
      //部门分页列表
      operationLogs: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      //listLoading: false,
      sels: [],//列表选中列

      saveFormVisible: false,//编辑界面是否显示
      saveLoading: false,
      saveFormRules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ]
      },
      //编辑界面数据
      /*saveForm: {
        name: '',
        sn: '',
        state: '',
        managerId: '',
        parentId: ''
      },*/


    }
  },
  methods: {

    /*getDeptTree() {
      this.$http.get("/department/deptTree").then(res => {
        this.options = res.data.resultObj;
        console.log(res);
      })
    },*/

    //当页码发生改变的时候，触发事件
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getOperationLogs();
    },
    //获取用户列表
    getOperationLogs() {
      //开启加载框
      this.listLoading = true;
      let param = {
        "currentPage": this.currentPage,
        "pageSize": this.pageSize,
        "keyword": this.filters.keyword
      };
      this.$http.post("/operationLogs/selectByQueryPage", param).then(res => {
        let {success, resultObj} = res.data;
        if (success) {
          this.operationLogs = resultObj.list;
          this.total = resultObj.total;
          console.log(resultObj);
        }
        //关闭加载框
        this.listLoading = false;
      })
    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        this.$http.delete("/operationLogs/delete/" + row.id).then(res => {
          let {success} = res.data;
          //如果成功
          if (success) {
            //刷新界面
            this.getOperationLogs();
          } else {
            this.$message({
              message: '删除失败',
              type: 'error'
            });
          }
          this.listLoading = false;
        })
      }).catch(() => {

      });
    },
    //显示编辑界面
    /*handlesave: function (index, row) {
      this.title = "编辑";
      this.getManagers();
      this.getDeptTree();
      this.saveFormVisible = true;
      this.saveForm = Object.assign({}, row);
    },*/
    //显示新增界面
    /*handleAdd: function () {
      this.title = "新增";
      this.saveFormVisible = true;
      this.saveForm = {
        name: '',
        sn: '',
        state: '',
        managerId: '',
        parentId: ''
      };
      this.getManagers();
      this.getDeptTree();
    },*/

    /*saveSubmit: function () {
      this.$refs.saveForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            console.log(this.saveForm);
            console.log(this.saveForm.parentId);
            //将数组parentId转为字符串
            this.saveForm.parentId = this.saveForm.parentId.join(",");
            //截取parentId中最后一个","后面的数赋值给parentId
            this.saveForm.parentId = this.saveForm.parentId.substring(this.saveForm.parentId.lastIndexOf(",") + 1);


            this.$http.put("/department/save", this.saveForm).then(res => {
              let {success} = res.data;
              if (success) {
                //刷新界面
                this.getDepartments();
                this.$message({
                  message: '提交成功',
                  type: 'success'
                });
                //关闭加载框
                this.addLoading = false;
                //关闭模态框
                this.saveFormVisible = false;
              } else {
                this.$message({
                  message: '提交失败',
                  type: 'error'
                });
              }
            })
          });
        }
      });
    },*/
    //选择每页显示记录条数
    handleSizeChange(curentPage) {
      this.pageSize = curentPage
      this.getOperationLogs();
    },
    selsChange: function (sels) {
      this.sels = sels;
    },

    /*getManagers() {
      this.$http.patch("/employee/selectAll").then(res => {
        this.managers = res.data.resultObj;

      })
    },*/

    //批量删除
    batchRemove: function () {
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        let ids = this.sels.map(item => item.id);
        this.$http.patch("/operationLogs/patchDelete", ids).then(res => {
          let {success} = res.data;
          if (success) {
            //刷新界面
            this.getOperationLogs();
          } else {
            this.$message({
              message: '删除失败',
              type: 'error'
            });
          }
        })
      }).catch(() => {

      });
    }
  },
  mounted() {
    this.getOperationLogs();
  }
}

</script>

<style scoped>

</style>